{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "afd55886-5f5b-4794-838e-ef8179fb0394",
   "metadata": {},
   "source": [
    "##### **** These pip installs need to be adapted to use the appropriate release level. Alternatively, The venv running the jupyter lab could be pre-configured with a requirement file that includes the right release. Example for transform developers working from git clone:\n",
    "```\n",
    "make venv \n",
    "source venv/bin/activate \n",
    "pip install jupyterlab\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c45c3c6-e4d7-4e61-8de6-32d61f2ce695",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%capture\n",
    "## This is here as a reference only\n",
    "# Users and application developers must use the right tag for the latest from pypi\n",
    "!pip install data-prep-toolkit\n",
    "!pip install \"data-prep-toolkit-transforms[ray, text_encoder]\"\n",
    "!pip install -U ipywidgets"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ebf1f782-0e61-485c-8670-81066beb734c",
   "metadata": {
    "tags": []
   },
   "source": [
    "##### ***** Import required classes and modules"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2a12abc-9460-4e45-8961-873b48a9ab19",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dpk_text_encoder.runtime import TextEncoder\n",
    "from data_processing.utils import GB"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72a40852-5a72-4a08-8dcf-7103b55975d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "!rm -fr output"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7234563c-2924-4150-8a31-4aec98c1bf33",
   "metadata": {},
   "source": [
    "##### ***** Setup runtime parameters for this transform"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b70a770f",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=TextEncoder(input_folder= \"test-data/input/\", \n",
    "               output_folder= \"output/\", \n",
    "               text_encoder_model_name = 'ibm-granite/granite-embedding-small-english-r2',\n",
    "               text_encoder_lanceDB_data_uri = 'output/test.db/test.lance/',\n",
    "               text_encoder_lanceDB_batch_size = 10,\n",
    "               text_encoder_embedding_batch_size = 5,\n",
    "               text_encoder_lanceDB_fragments_json_folder = 'output/fragments_json/',\n",
    "               text_encoder_lanceDB_table_name = 'test'\n",
    "               ).transform()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6cc0f5ea-9e39-4d9a-af4a-374a1ffb4616",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.argv = ['dpk_text_encoder/lance_commit.py', '--lanceDB_uri', 'output/test.db', \n",
    "            'lanceDB_data_uri', 'output/test.db/test.lance',\n",
    "            'lanceDB_table_name', 'test',\n",
    "            'lanceDB_fragments_json_foler', 'output/fragments_json',\n",
    "            'lanceDB_table_schema_folder', 'output/']\n",
    "%run dpk_text_encoder/lance_commit.py --lanceDB_uri \"output/test.db\" --lanceDB_data_uri \"output/test.db/test.lance\" --lanceDB_table_name \"test\" --lanceDB_fragments_json_folder \"output/fragments_json/\" --lanceDB_table_schema_folder \"output/\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3df5adf-4717-4a03-864d-9151cd3f134b",
   "metadata": {},
   "source": [
    "##### **** The specified folder will include the transformed parquet files."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7276fe84-6512-4605-ab65-747351e13a7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob\n",
    "glob.glob(\"output/*\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "998193ec-b442-4476-8387-d5f849d24647",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (text_encoder)",
   "language": "python",
   "name": "text_encoder"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
